package com.warmlight.voicepacket.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.github.siyamed.shapeimageview.CircularImageView;
import com.github.siyamed.shapeimageview.RoundedImageView;
import com.warmlight.voicepacket.R;
import com.warmlight.voicepacket.base.SingleRecycleViewAdapter;

import java.util.Map;

public class MyMessageListAdapter extends SingleRecycleViewAdapter<Map<String,String>> {

    public MyMessageListAdapter(Context context) {
        super(context);
    }

    @Override
    public HashViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_my_message,parent,false);
        HashViewHolder holder = new HashViewHolder(view);
        holder.putView(R.id.ci_head_img);
        holder.putView(R.id.tv_nickname);
        holder.putView(R.id.tv_zan);
        holder.putView(R.id.tv_ping);
        holder.putView(R.id.tv_time);
        holder.putView(R.id.iv_img);

        return holder;
    }

    @Override
    public void onBindViewHolder(HashViewHolder holder, int position) {
        Map<String, String> item = getItem(position);
        CircularImageView ci_head_img = (CircularImageView) holder.findView(R.id.ci_head_img);
        TextView tv_nickname = (TextView) holder.findView(R.id.tv_nickname);
        TextView tv_zan = (TextView) holder.findView(R.id.tv_zan);
        TextView tv_ping = (TextView) holder.findView(R.id.tv_ping);
        TextView tv_time = (TextView) holder.findView(R.id.tv_time);
        RoundedImageView iv_img = (RoundedImageView) holder.findView(R.id.iv_img);

        String text = "你好哈哈哈哈哈哈哈哈哈哈或或或或或或或或或或或或或或或或或查看详情";

        if (text.contains("查看详情")){
            int i = text.indexOf("查看详情");
            SpannableString spannableString = new SpannableString(text);
            spannableString.setSpan(new ClickableSpan() {
                @Override
                public void updateDrawState(TextPaint ds) {
                    ds.setColor(Color.RED);  //设置下划线颜色
                    ds.setUnderlineText(true);  // 显示下划线
                }

                @Override
                public void onClick(View view) {     // TextView点击事件

                }

            }, i, i+4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            tv_ping.setText(spannableString);
            tv_ping.setHighlightColor(mContext.getResources().getColor(android.R.color.transparent));
            tv_ping.setMovementMethod(LinkMovementMethod.getInstance());

        }else{
            tv_ping.setText(text);
        }

    }
}
